home *** CD-ROM | disk | FTP | other *** search
/ Star Trek Starfleet Academy Mini Omnipedia / MINI_OMNI.ISO / pc / omni_v2.dxr / 00373_Parsing & Interpreting.ls < prev    next >
Encoding:
Text File  |  1996-04-15  |  7.8 KB  |  284 lines

  1. global gholdTheFTword, gBeginCurlyQ, gEndCurlyQ, oIndexSlider, gStashedSEEList
  2.  
  3. on hIsaQuote pChar
  4.   set pChar to charToNum(pChar)
  5.   if (pChar = 39) or (pChar = 34) or (pChar = charToNum(gBeginCurlyQ)) then
  6.     return 1
  7.   else
  8.     return 0
  9.   end if
  10. end
  11.  
  12. on hIsaCastMem pName
  13.   if the number of cast pName < 0 then
  14.     return 0
  15.   else
  16.     return 1
  17.   end if
  18. end
  19.  
  20. on hIsaRomanDate pNtry
  21.   set lx to value(char 1 to 4 of pNtry)
  22.   if lx = EMPTY then
  23.     return 0
  24.   end if
  25.   if (lx >= 1800) and (lx <= 2400) then
  26.     return 1
  27.   else
  28.     return 0
  29.   end if
  30. end
  31.  
  32. on hPhraseEndsWith pPhrase, pWord
  33.   set Lnum to the number of words in pPhrase
  34.   if word Lnum of pPhrase = pWord then
  35.     return 1
  36.   else
  37.     return 0
  38.   end if
  39. end
  40.  
  41. on hGetLastWord pPhrase
  42.   set Lnum to the number of words in pPhrase
  43.   return word Lnum of pPhrase
  44. end
  45.  
  46. on hWordEndsWith pWord, pChar
  47.   set Lnum to the number of chars in pWord
  48.   if char Lnum of pWord = pChar then
  49.     return 1
  50.   else
  51.     return 0
  52.   end if
  53. end
  54.  
  55. on hLastNameFirst pTheEntry
  56.   hReportStatus("No immediate match. Altering search parameters...")
  57.   set vNum to the number of words in pTheEntry
  58.   if vNum > 1 then
  59.     set vLastWord to word vNum of pTheEntry
  60.     if word 2 of pTheEntry = "La" then
  61.       set pTheEntry to word 2 to vNum of pTheEntry & ", " & word 1 of pTheEntry
  62.     else
  63.       set vFirstWords to word 1 to vNum - 1 of pTheEntry
  64.       set pTheEntry to vLastWord & ", " & vFirstWords
  65.       set vhold to word the number of words in pTheEntry of pTheEntry
  66.       set vhold to hZapEnd(vhold, 32)
  67.       set pTheEntry to word 1 to vNum - 1 of pTheEntry & " " & vhold
  68.     end if
  69.   end if
  70.   return pTheEntry
  71. end
  72.  
  73. on hIsADoctor pTheEntry
  74.   hReportStatus("No immediate match. Altering search parameters...")
  75.   hSayProgress(#WOR)
  76.   set vNum to the number of words in pTheEntry
  77.   if vNum > 1 then
  78.     set vLastWord to word vNum of pTheEntry
  79.     set vFirstWords to word 1 to vNum - 1 of pTheEntry
  80.     set pTheEntry to vLastWord & ", " & vFirstWords
  81.     set vhold to word the number of words in pTheEntry of pTheEntry
  82.     set vhold to hZapEnd(vhold, 32)
  83.     set pTheEntry to word 1 to vNum - 1 of pTheEntry & " Dr. " & vhold
  84.   end if
  85.   return pTheEntry
  86. end
  87.  
  88. on hTryCap pTheEntry
  89.   hReportStatus("No immediate match. Altering search parameters...")
  90.   put hCapitalize(char 1 of word 1 of pTheEntry) into char 1 of word 1 of pTheEntry
  91.   return pTheEntry
  92. end
  93.  
  94. on hTryHarder pTheEntry
  95.   global gComputerTypeK
  96.   hReportStatus("No immediate match. Altering search parameters...")
  97.   set Lnum to the number of words in pTheEntry
  98.   if hWordEndsWith(word Lnum of pTheEntry, "s") then
  99.     set Llastchar to the number of chars in word Lnum of pTheEntry
  100.     delete char Llastchar of word Lnum of pTheEntry
  101.   end if
  102.   if hWordEndsWith(word Lnum of pTheEntry, "'") then
  103.     set Llastchar to the number of chars in word Lnum of pTheEntry
  104.     delete char Llastchar of word Lnum of pTheEntry
  105.   end if
  106.   if gComputerTypeK = #mac then
  107.     set curlyOffset to offset(numToChar(213), pTheEntry)
  108.     set numOfChars to the number of chars in pTheEntry
  109.     if curlyOffset > 0 then
  110.       set pTheEntry to char 1 to curlyOffset - 1 of pTheEntry & "'" & char curlyOffset + 1 to numOfChars of pTheEntry
  111.     end if
  112.   end if
  113.   return pTheEntry
  114. end
  115.  
  116. on htryevenharder pTheEntry
  117. end
  118.  
  119. on hTweaktoTitle pChars
  120.   if hIsaQuote(char 1 of pChars) then
  121.     put numToChar(210) into char 1 of pChars
  122.   else
  123.     put numToChar(210) before pChars
  124.   end if
  125.   return pChars
  126. end
  127.  
  128. on htransposearticles pWords
  129.   if the number of words in pWords > 1 then
  130.     set lFirst to word 1 of pWords
  131.     if ((lFirst contains "The") and (length(lFirst) <= 4)) or ((char 2 of lFirst = "A") and (length(lFirst) = 2)) then
  132.       set Lnum to the number of words in pWords
  133.       if lFirst starts gBeginCurlyQ then
  134.         set Linit to gBeginCurlyQ
  135.         delete char 1 of lFirst
  136.         set Lend to the number of chars in word Lnum of pWords
  137.         delete char Lend of word Lnum of pWords
  138.         set Lfinal to gEndCurlyQ
  139.       else
  140.         set Linit to EMPTY
  141.         set Lfinal to EMPTY
  142.       end if
  143.       set Lnew to Linit & word 2 to Lnum of pWords & ", " & lFirst & Lfinal
  144.       return Lnew
  145.     end if
  146.   end if
  147.   return pWords
  148. end
  149.  
  150. on hcleanup x
  151.   if voidp(x) then
  152.     return 
  153.   end if
  154.   repeat while char 1 of x = " "
  155.     delete char 1 of x
  156.   end repeat
  157.   repeat while char length(x) of x = " "
  158.     delete char length(x) of x
  159.   end repeat
  160.   set vItemsToStrip to " ,.()[]/\!?" & QUOTE & "‚Äù"
  161.   if vItemsToStrip contains char 1 of x then
  162.     delete char 1 of x
  163.   end if
  164.   set y to length(x)
  165.   set vFound to 1
  166.   repeat while vFound = 1
  167.     if vItemsToStrip contains char y of x then
  168.       delete char y of x
  169.       set y to y - 1
  170.       next repeat
  171.     end if
  172.     set vFound to 0
  173.   end repeat
  174.   if QUOTE & "‚Äú" contains char 1 of x then
  175.     delete char 1 of x
  176.   end if
  177.   return x
  178. end
  179.  
  180. on hStripTrailingReturns pPhrase
  181.   set Lsize to the number of chars in pPhrase
  182.   set Llimit to Lsize - 5
  183.   repeat with n = Lsize down to Llimit
  184.     if charToNum(char n of pPhrase) = 13 then
  185.       delete char n of pPhrase
  186.     end if
  187.   end repeat
  188.   repeat while charToNum(char length(pPhrase) of pPhrase) = 32
  189.     delete char length(pPhrase) of pPhrase
  190.   end repeat
  191.   if charToNum(char length(pPhrase) of pPhrase) = 46 then
  192.     delete char length(pPhrase) of pPhrase
  193.   end if
  194.   return pPhrase
  195. end
  196.  
  197. on hIsaSeeListItem pTheword, pThechunk
  198.   if not (pThechunk contains ";") then
  199.     return(void)
  200.   else
  201.     set Lthisword to pTheword
  202.     if Lthisword contains ";" then
  203.       set Lthisword to char 1 to length(Lthisword) - 1 of Lthisword
  204.     end if
  205.     set tidl to the itemDelimiter
  206.     set the itemDelimiter to ";"
  207.     set z to the number of items in pThechunk
  208.     repeat with i = 1 to z
  209.       set Ltempstr to item i of pThechunk
  210.       if Ltempstr contains Lthisword then
  211.         set the itemDelimiter to tidl
  212.         return Ltempstr
  213.         exit repeat
  214.       end if
  215.     end repeat
  216.     set the itemDelimiter to tidl
  217.     return(void)
  218.   end if
  219. end
  220.  
  221. on hCompileSEEtoFound pTheWordNum, pthefield
  222.   hReportStatus("Compiling related entries from SEE list...")
  223.   set pThechunk to hExtractSeeList(pTheWordNum, pthefield)
  224.   set tidl to the itemDelimiter
  225.   set the itemDelimiter to ";"
  226.   set z to the number of items in pThechunk
  227.   set Ltemplist to [:]
  228.   repeat with i = 1 to z
  229.     set LanNtry to item i of pThechunk
  230.     if char 1 of LanNtry = " " then
  231.       delete char 1 of LanNtry
  232.     end if
  233.     if LanNtry <> EMPTY then
  234.       setaProp(Ltemplist, LanNtry, [])
  235.     end if
  236.   end repeat
  237.   set the itemDelimiter to tidl
  238.   hSwitchFTsearchscope(#ENCY)
  239.   hSetMode(#FoundSet)
  240.   set gStashedSEEList to Ltemplist
  241.   mSetupSEEList(oIndexScroller)
  242.   set kall to mGetThisEntryName(oIndexMediator, #FoundSet, 1, 1)
  243.   mReDefineSlider(oIndexSlider, 1, z - 6, 1)
  244.   mSetSlider(oIndexSlider, 1)
  245.   set k to char 1 of kall
  246.   hSetIndex(k, kall)
  247.   hProcess(kall)
  248. end
  249.  
  250. on hExtractSeeList pTheWordNum, pthefield
  251.   global gkeylist, gKeyCount, gTheFTword
  252.   sort(gkeylist)
  253.   set Lpointer to findPosNear(gkeylist, pTheWordNum)
  254.   set Lstylehere to getAt(getAt(gkeylist, Lpointer), 2)
  255.   if (Lstylehere = #b) or (Lstylehere = #bi) then
  256.   else
  257.     set Lpointer to Lpointer + 1
  258.     set Lstylehere to getAt(getAt(gkeylist, Lpointer), 2)
  259.     if (Lstylehere = #b) or (Lstylehere = #bi) then
  260.     else
  261.       beep()
  262.       abort()
  263.     end if
  264.   end if
  265.   set Lchunkstart to getPropAt(gkeylist, Lpointer)
  266.   set Lnumofwords to 0
  267.   repeat with i = Lpointer to gKeyCount
  268.     set Lastyle to getAt(getAt(gkeylist, i), 2)
  269.     if (Lastyle = #b) or (Lastyle = #bi) then
  270.       set Lchunkend to getPropAt(gkeylist, i)
  271.       set Lnumofwords to Lnumofwords + getAt(getAt(gkeylist, i), 1)
  272.       next repeat
  273.     end if
  274.     exit repeat
  275.   end repeat
  276.   if Lchunkend < Lchunkstart then
  277.     beep()
  278.     abort()
  279.   end if
  280.   set Ltheblock to word Lchunkstart to Lchunkstart + Lnumofwords of field pthefield
  281.   set gTheFTword to "[" & line 1 of field pthefield & "]"
  282.   return hStripTrailingReturns(Ltheblock)
  283. end
  284.